package com.xbd.flex.init;

import com.mybatisflex.core.query.QueryWrapper;
import com.xbd.flex.entity.User;
import com.xbd.flex.entity.User2;
import com.xbd.flex.mapper.User2Mapper;
import com.xbd.flex.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class UserInit implements CommandLineRunner {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private User2Mapper user2Mapper;


    public void run(String... args) throws Exception {
        long count = userMapper.selectCountByQuery(new QueryWrapper());
        if (count == 0) {
            User user = new User();
            user.setUsername("admin");
            user.setPassword("admin");
            userMapper.insert(user);
        }
        long count2 = user2Mapper.selectCountByQuery(QueryWrapper.create());
        if (count2 == 0) {
            User2 user2 = new User2();
            user2.setUsername("admin");
            user2.setPassword("admin");
            user2Mapper.insert(user2);
        }
    }
}
